<?php

namespace common\models;

use yii\base\Model;
use yii\web\UploadedFile;

class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $xlsFile;
    const PATHFILE = 'uploads/';  //上传路径

    public function rules()
    {
        /*return [
            [['xlsFile'], 'file'],
            //[['xlsFile'], 'file', 'skipOnEmpty' => false],
           // [['xlsFile'], 'file', 'extensions' => 'xls, xlsx','maxSize'=>1024*1024*20],
        ];*/

        return [
            ['xlsFile', 'file', 'extensions' => ['xls', 'xlsx', /*'et'*/], 'checkExtensionByMimeType' => false, 'maxSize' => 1024 * 1024 * 1024],
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
            return true;
        } else {
            return false;
        }
    }
}

?>